package com.xjgc.eip.panel.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xjgc.common.entity.ReturnResult;
import com.xjgc.common.utils.PushDataUtil;
import com.xjgc.common.utils.TransNoUitl;
import com.xjgc.eip.panel.entity.ZxjEipPcjh;
import com.xjgc.eip.panel.mapper.ZxjEipPcjhMapper;
import com.xjgc.eip.panel.service.ZxjEipPcjhService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhanghongbin
 * @since 2019-11-17
 */
@Service
public class ZxjEipPcjhServiceImpl extends ServiceImpl<ZxjEipPcjhMapper, ZxjEipPcjh> implements ZxjEipPcjhService {
    @Value("pcjhUrl")
    public String url;
    @Transactional
    public void producePlan(){

        QueryWrapper<ZxjEipPcjh> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("ioflag","0");
        List<ZxjEipPcjh> list = this.list(queryWrapper);
        ReturnResult returnResult = new ReturnResult();
        returnResult.setData(list);
        String orisys="0";
        String transno=TransNoUitl.genTransNo();
        String operatetype="add";
        for (ZxjEipPcjh zes:list) {
            //header数据
            if ("1".equals(zes.getStatus())){//更新
                operatetype="update";
            }
            //body数据  就是zex
            //String url="http://10.10.7.70:22108/api/supplier-production-schedule";
            String returnString= PushDataUtil.pushData(url,orisys,transno,operatetype,zes);
            if(returnString==null){
                System.out.println("=======================》》》》》》》》》》无返回数据");
                return;
            }else{
                JSONObject jsonObject=JSONObject.parseObject(returnString);
                String status=jsonObject.getString("status");
                String message=jsonObject.getString("message");
                if("10000".equals(status)){
                    zes.setIoflag("0");
                    zes.setMessage(message);
                    this.updateById(zes);
                }else{
                    zes.setIoflag(status);
                    zes.setMessage(message);
                    this.updateById(zes);
                };

            }
        }
    }
}
